package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class StudentManager implements DaoInterface<Student>{
	private ArrayList<Student> arList;

	public StudentManager() {
		arList = new ArrayList<>();
	}

	public StudentManager(ArrayList<Student> arList) {
		this.arList = arList;
	}
	
	public void prnList(){
		prnHeader();
		for(Student std: arList){
			System.out.println(std);
		}
	}
	
	public void prnHeader() {
		String header = String.format("%3s\t%5s\t%4s\t%4s\t%4s\t%4s\t%5s","학번","성명","국어","영어","수학","총점","평균");
		System.out.println(header);
	}

	@Override
	public void addItem(Student item) {
		arList.add(item);		
	}

	@Override
	public Student searchItem(Student item) {
		if (arList.contains(item)){
			return arList.get(arList.indexOf(item));
		}else{
			return null;
		}
	}

	@Override
	public void updateItem(Student item) {
		arList.set(arList.indexOf(item), item);
/*		Student temp = arList.get(arList.indexOf(item));
		temp.setStdNum(item.getStdNum());
		temp.setStdName(item.getStdName());
		temp.setKorScore(item.getKorScore());
		temp.setEngScore(item.getEngScore());
		temp.setMathScore(item.getMathScore());*/
	}

	@Override
	public void delItem(Student item) {
		if (arList.contains(item)){
			arList.remove(arList.indexOf(item));
		}else{
			System.out.println("해당 학생 정보 없음");
		}
	}
}
